<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no">
    <meta http-equiv="X-UA-Compatible" content="ie=edge,chrome=1">
    <meta name="referrer" content="never">
    <title>获取元素于页面距离新方法</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }
        ul {
            list-style: none;
        }

        .box{
            position: absolute;
            top: 50px;
            left: 100px;
            width: 200px;
            height: 200px;
            /* margin: 50px; */
            padding: 30px;
            background-color: #ff9000;
            border: 30px solid #ff0;
        }

        .inner {
            position: relative;
            width: 130px;
            height: 130px;
            padding: 10px;
            margin: 20px;
            background-color: #00f;
        }

        .insert {
            width: 50px;
            height: 50px;
            margin: 40px;
            background-color: #0f0;
        }
    </style>
</head>
<body>
    <div class="box">

        <div class="inner">

            <div class="insert"></div>
        </div>
    </div>

    <script type="text/javascript">
        var box = document.querySelector(".box"),
            inner = document.querySelector(".inner"),
            insert = document.querySelector(".insert");

        console.log("box与页面的距离", box.getBoundingClientRect().left);
        console.log("inner与页面的距离", inner.getBoundingClientRect().left);
        console.log("insert与页面的距离", insert.getBoundingClientRect().left);
    </script>
</body>
</html>